package com.itheima.service.impl;

/*import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MemberDao;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
@Service(version = "1.0.0",interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        Member member = memberDao.findByTelephone(telephone);
        return member;
    }

    @Override
    public Integer save(Member newMember) {
        memberDao.save(newMember);
        return newMember.getId();
    }
}*/
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MemberDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;

import javax.annotation.Resource;
import java.util.List;

@Service(version = "1.0.0",interfaceClass = MemberService.class)
public  class MemberServiceImpl implements MemberService {

    @Resource
    private MemberDao memberDao;

    @Override
    public Member findByTelephone(String telephone) {
        Member member = memberDao.findByTelephone(telephone);
        return member;
    }

    @Override
    public Integer save(Member newMember) {
        memberDao.save(newMember);
        return newMember.getId();
    }

    @Override
    public Result findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Member> memberPage=memberDao.findByCondition(queryPageBean.getQueryString());
        PageResult pageResult = new PageResult();
        pageResult.setRows(memberPage.getResult());
        pageResult.setTotal(memberPage.getTotal());
        return Result.success(pageResult);

    }

    @Override
    public Result add(Member member) {
        this.memberDao.add(member);
        return Result.success(null);
    }

    @Override
    public Result update(Member member) {
        this.memberDao.update(member);
        return Result.success(null);
    }

    @Override
    public Result findAll() {
        List<Member> all=this.memberDao.findAll();
        return Result.success(all);
    }

    @Override
    public Result findById(Integer id) {
      Member member=  this.memberDao.findById(id);
        return Result.success(member);
    }

    @Override
    public Result delete(Integer id) {
        this.memberDao.delete(id);
        return Result.success(null);
    }


}











